<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/include/page.jsp"%>
<!DOCTYPE HTML>
<html>
	<head>
		<title>品牌添加 - 商城后台</title>
		<%@ include file="/common/include/title.jsp"%>
		<script language="javascript" type="text/javascript" src="${rootpath }/common/resource/My97DatePicker/WdatePicker.js"></script>
		
		<script type="text/javascript" charset="utf-8" src="${rootpath }/ueditor/ueditor.config.js"></script>
	    <script type="text/javascript" charset="utf-8" src="${rootpath }/ueditor/ueditor.all.min.js"> </script>
	    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
	    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
	    <script type="text/javascript" charset="utf-8" src="${rootpath }/ueditor/lang/zh-cn/zh-cn.js"></script>
	    <script type="text/javascript">
	    	/*
	    		分类的ID
	    	*/
	    	function changeCate(cateId)
	    	{
	    		//alert('-----'+ $("#" + cateId + " option").length)
	    		var specJSON = ""; 
	    		$("#" + cateId + " option").each(function()
   				{
	    			if($(this).prop("selected"))
    				{
    					/* 选择的就是这个option */
	   					//alert($(this).attr("value") + "=====>" + $(this).attr("json") + "---->" + $(this).prop("selected"));
    					specJSON = $(this).attr("json");
    					//break ; 
    				}
   				});
	    		
	    		/* alert(specJSON)
	    		alert($.parseJSON(specJSON)) */
	    		eval("var json = " + specJSON) ; 
	    		//alert(json + "----")
	    		
	    		/*
	    		<div class='row cl'>
	    			<input type='hidden' name='spec_name' value='主体'/>
	    			<label class='form-label col-2'>主体</label>
	    		</div>
	    		<div class='row cl'>
					<label class='form-label col-2'><span class='c-red'>*</span>名称(用户看的)：</label>
					<input type='hidden' name='spec_name_key' value='系列'/>
					<div class='formControls col-10'>
						<select name='spec_name_value'>
							<option value=''></option>
						</select>
					</div>
				</div>
	    		*/
	    		var sb = "" ; 
	    		for(var i = 0 ; i < json.length ; i ++)
    			{
    				var jsonTemp = json[i] ; 
    				sb += "<div class='row cl'>";
    				sb +="	<label class='form-label col-2'>"+ jsonTemp.name + "</label>";
    				sb +="	<input type='hidden' name='spec_name_"+ i +"' value='"+ jsonTemp.name + "'/>" ;
    				sb +="	</div>"; 
    				for(var j = 0 ; j < jsonTemp.keys.length ; j ++)
   					{
    					var valTemp = jsonTemp.keys[j] ; 
    					var valValTemp = valTemp.values ; 
    					
			    		sb += "<div class='row cl'>" ;
			    		sb += "<label class='form-label col-2'><span class='c-red'>*</span>"+ valTemp.name +"：</label>" ; 
			    		sb += "<input type='hidden' name='spec_key_"+ i +"' value='"+ valTemp.name +"'/>"
			    		sb += "<div class='formControls col-10'>" ; 
			    		sb += "		<select name='spec_value_"+ i +"'>";
			    		for(var k = 0 ; k < valValTemp.length; k ++)
		    			{
				    		sb += "		<option value='"+ valValTemp[k] +"'>"+ valValTemp[k] +"</option>";
		    			}
		    			sb += "		</select>"; 
			    		sb += "	</div>" ; 
			    		sb += "</div>" ; 
   					
   					}
    			}
	    		// alert(sb)
	    		$("#cateDiv").html(sb);
	    	}
		</script>
	</head>
	<body>
		<div class="pd-20">
			<form action="${rootpath }/back/goods/goodsInsertSubmit.htm" method="post" class="form form-horizontal"
				enctype="multipart/form-data"
				id="form-article-add">
				<!-- <input type="hidden" name="logoPath" value=""> -->
				
				<div class="row cl">
					<div class="col-10 col-offset-2">
						<button class="btn btn-primary radius" type="submit">
							<i class="Hui-iconfont">&#xe632;</i> 保存
						</button>
						${info}
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-2"><span class="c-red">*</span>品牌：</label>
					<div class="formControls col-10">
						<select name="brandId">
							<c:forEach items="${requestScope.goodsBrandList }" var="brand" varStatus="stat">
								<option value="${brand.id }">${brand.name }</option>								
							</c:forEach>
						</select>
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-2"><span class="c-red">*</span>分类：</label>
					<div class="formControls col-10">
						<select name="cateId" onchange="return changeCate('cateId')" id="cateId">
							<c:forEach items="${requestScope.goodsCateTreeArr }" var="cateMap" varStatus="stat">
								<option json="${fn:replace(cateMap.spec,'"','\'')}" value="${cateMap.id }" ${cateMap.isLeaf == '0' ? 'disabled' : '' }>${cateMap.treeName }</option>								
							</c:forEach>
						</select>
					</div>
				</div>
				<div id="cateDiv">
				</div>
				<div class="row cl">
					<label class="form-label col-2"><span class="c-red">*</span>名称(用户看的)：</label>
					<div class="formControls col-10">
						<input type="text" class="input-text" value="" placeholder="" id=""
							name="name">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-2">标题(管理员)：</label>
					<div class="formControls col-10">
						<input type="text" class="input-text" value="" placeholder="" id=""
							name="title">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-2">url：</label>
					<div class="formControls col-10">
						<input type="text" class="input-text" value="" placeholder="" id=""
							name="url">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-2">重量：</label>
					<div class="formControls col-4">
						<input type="text" class="input-text" value="" placeholder="" id=""
							name="weight">
					</div>
					<label class="form-label col-2">库存量：</label>
					<div class="formControls col-4">
						<input type="text" class="input-text" value="" placeholder="" id=""
							name="remainNum">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-2">市场价：</label>
					<div class="formControls col-4">
						<input type="text" class="input-text" value="" placeholder="" id=""
							name="marketPrice">
					</div>
					<label class="form-label col-2">购买价：</label>
					<div class="formControls col-4">
						<input type="text" class="input-text" value="" placeholder="" id=""
							name="price">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-2"><span class="c-red">*</span>发布时间：</label>
					<div class="formControls col-2">
						<input name="pubTimeStr" class="input-text" value="<fmt:formatDate value="${sys_now }" pattern="yyyy-MM-dd HH:mm:ss"/>" style="width:150px;" type="text" placeholder="发布时间" 
						onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-2"><span class="c-red">*</span>图片：</label>
					<div class="formControls col-2">
						<input name="file" class="input-text" type="file"/>
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-2"><span class="c-red">*</span>状态：</label>
					<div class="formControls col-2">
						<input type="radio" name="status" id="status1" value="1" checked="checked"><label for="status1">启用</label>
						<input type="radio" name="status" id="status0" value="0"><label for="status0">禁用</label>
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-2">内容：</label>
					<div class="formControls col-10">
						<!-- 百度编辑器的内容 -->
						<script id="editor" type="text/plain" name="content" style="width:800px;height:500px;"></script>
					</div>
				</div>
			</form>
		</div>
		</div>
	</body>
</html>
<script type="text/javascript">
//实例化编辑器
//建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
/* editor是id为editor百度编辑器存储的位置 */
var ue = UE.getEditor('editor');
</script>